<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/3 0003
 * Time: 18:58
 */

namespace app\plat\controller;


use think\Db;

class Index extends Base
{
    public $table;
    public function index()
    {

        $this->assign('admin',$this->admin);
        return $this->fetch();
    }

    public function home()
    {

    }

    //    退出登录
    public function logout()
    {
        session('plat',null);
        $this->success('退出成功',url('login/index'));
    }

    /**
     * 修改自己密码
     */
    public function edit()
    {
        return $this->fetch();
    }

    public function ajax_verify_password()
    {
        $password = md5(input('password'));
        $old = Db::name('admin')->where('id',$this->admin['id'])->value('password');
        if($password == $old){
            echo api_return(1,'密码正确');
        }else{
            echo  api_return(0,'密码不正确');
        }
    }

    public function ajax_edit()
    {
        $old = md5(input('original_password'));
        $data['password'] = md5(input('password'));
        $password = Db::name('admin')->where('id',$this->admin['id'])->value('password');
        if($password != $old){
            echo api_return(0,'密码不正确');
            exit;
        }
        $data['modtime'] = time();
        $a = Db::name('admin')->where('id',$this->admin['id'])->update($data);
        if($a){
            echo api_return(1,'修改成功');
        }else{
            echo api_return(0,'修改失败');
        }
    }
}